package com.party.core.service.enterpriseservice.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.enterpriseservice.EpServiceReadDao;
import com.party.core.dao.write.enterpriseservice.EpServiceWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.enterpriseservice.EpService;
import com.party.core.service.enterpriseservice.IEpServiceService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @program: party
 * @description: 服务service实现
 * @author: Hua Qunhao
 * @create: 2019-01-08 15:51
 */
@Service("EpServiceService")
public class EpServiceService implements IEpServiceService {
    @Autowired
    private EpServiceReadDao epServiceReadDao;

    @Autowired
    private EpServiceWriteDao epServiceWriteDao;

    @Override
    public String insert(EpService epService) {
        BaseModel.preInsert(epService);
        boolean result = epServiceWriteDao.insert(epService);
        if (result) {
            return epService.getId();
        }
        return null;
    }

    @Override
    public boolean update(EpService epService) {
        epService.setUpdateDate(new Date());
        return epServiceWriteDao.update(epService);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epServiceWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epServiceWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epServiceWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epServiceWriteDao.batchDelete(ids);
    }

    @Override
    public EpService get(String id) {
        return epServiceReadDao.get(id);
    }

    @Override
    public List<EpService> listPage(EpService epService, Page page) {
        return epServiceReadDao.listPage(epService, page);
    }

    @Override
    public List<EpService> list(EpService epService) {
        return epServiceReadDao.listPage(epService,null);
    }

    @Override
    public List<EpService> batchList(Set<String> ids, EpService epService, Page page) {
        if (CollectionUtils.isEmpty(ids)){
            return Collections.EMPTY_LIST;
        }
        return epServiceReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public List<EpService> weblistPage(EpService epService, Map<String, Object> params, Page page) {
        return epServiceReadDao.weblistPage(epService,params,page);
    }
}
